import csv
import numpy as np
import stru
import training

sampleSize=1000

def gett(path):
    csv_reader = csv.reader(open(path))
    table=np.zeros((61,2))
    trank=np.zeros((61))
    isFirst=True
    i=0
    for row in csv_reader:
        if isFirst:
            isFirst=False
            continue
        table[i][0]=float(row[2]) # 分数
        table[i][1]=int(row[11]) # 时间
        trank[i] = int(row[3])  # 排名
        i+=1

    return [table,trank]

def genSample(path,X,Y,num):
    num*=sampleSize
    t=gett(path)
    table=t[0]
    trank=t[1]
    for i in range(sampleSize):
        result=stru.dropout(table,trank)
        X[num + i]=result["sample"]
        Y[num + i] = result["result"]

X = np.zeros((6*sampleSize,61,2))
Y = np.zeros((6*sampleSize,2))
genSample("D:/test/高二期中.csv",X,Y,0)
genSample("D:/test/高二上月考.csv",X,Y,1)
genSample("D:/test/高二下期中.csv",X,Y,2)
genSample("D:/test/高一下期末.csv",X,Y,3)
genSample("D:/test/高一下期中.csv",X,Y,4)
genSample("D:/test/高一下月考.csv",X,Y,5)

for i in Y:
    print(i)

training.fit(X,Y,6*sampleSize)